﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.Web.Farmer
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					Guid FarmerID=new Guid(Request.Params["id"]);
					ShowInfo(FarmerID);
				}
			}
		}
			
	private void ShowInfo(Guid FarmerID)
	{
		Things.BLL.Farmer bll=new Things.BLL.Farmer();
		Things.Model.Farmer model=bll.GetModel(FarmerID);
		this.lblFarmerID.Text=model.FarmerID.ToString();
		this.txtFarmerName.Text=model.FarmerName;
		this.txtSex.Text=model.Sex;
		this.txtAddress.Text=model.Address;
		this.txtTelPhone.Text=model.TelPhone;
		this.txtMobilePhone.Text=model.MobilePhone;
		

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtFarmerName.Text.Trim().Length==0)
			{
				strErr+="农户姓名不能为空！\\n";	
			}
			if(this.txtSex.Text.Trim().Length==0)
			{
				strErr+="性别不能为空！\\n";	
			}
			if(this.txtAddress.Text.Trim().Length==0)
			{
				strErr+="农户住址不能为空！\\n";	
			}
			if(this.txtTelPhone.Text.Trim().Length==0)
			{
				strErr+="固定电话不能为空！\\n";	
			}
			if(this.txtMobilePhone.Text.Trim().Length==0)
			{
				strErr+="移动电话不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			Guid FarmerID= new Guid(this.lblFarmerID.Text);
			string FarmerName=this.txtFarmerName.Text;
			string Sex=this.txtSex.Text;
			string Address=this.txtAddress.Text;
			string TelPhone=this.txtTelPhone.Text;
			string MobilePhone=this.txtMobilePhone.Text;
			bool IsDeleted=false;


			Things.Model.Farmer model=new Things.Model.Farmer();
			model.FarmerID=FarmerID;
			model.FarmerName=FarmerName;
			model.Sex=Sex;
			model.Address=Address;
			model.TelPhone=TelPhone;
			model.MobilePhone=MobilePhone;
			model.IsDeleted=IsDeleted;

			Things.BLL.Farmer bll=new Things.BLL.Farmer();
			bll.Update(model);
			Things.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
